# -*- coding：utf-8 -*-

from datetime import datetime
from elasticsearch_dsl import Document, Date, Integer, Keyword, Text, connections, Completion
from elasticsearch_dsl.analysis import CustomAnalysis

from elasticsearch_dsl.analysis import CustomAnalyzer as _CustomAmalyzer
from elasticsearch_dsl.connections import connections
connections.create_connection(hosts=['localhost'])


class CustomAnalysis(CustomAnalysis):
    def get_definition(self):
        return []


ik_analyzer = CustomAnalysis("ik_max_word", filter=["lowercase"])


class ArticleType(Document):
    # 思否在线文章类型
    suggest = Completion(analyzer=ik_analyzer)
    title = Text(analyzer="ik_max_word")
    create_date = Date()
    url = Keyword()
    url_object_id = Keyword()
    front_image_url = Keyword()
    front_image_path = Keyword()
    read_volume = Integer()
    fav_nums = Integer()
    article_text = Keyword()

    class Index:
        name = 'sifou'
        doc_type = "article"
        settings = {
            "number_of_shards": 5,
        }


if __name__ == "__main__":
    ArticleType.init()
